package com.qn.visitor.intercept;

import com.qn.visitor.intercept.handler.BaseInterceptHandler;
import com.qn.visitor.model.bo.intercept.InterceptResult;
import com.qn.visitor.model.bo.intercept.InterceptRule;
import com.qn.visitor.model.bo.intercept.InterceptSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
 * qingniu-cloud user source analysis
 *
 * @Author: TXG
 * @Date: 2024/6/11
 * @Version V0.0.2
 */
@Component
public class InterceptContext {
    @Autowired
    BaseInterceptHandler handler;
    public InterceptResult intercept(InterceptSource source, InterceptRule rule) {
        if (rule == null) {
            return new InterceptResult();
        }
        //执行
        BaseInterceptHandler handlerResult = handler.intercept(rule, source);
        InterceptResult result = new InterceptResult();
        if (handlerResult != null) {
            result.setState(1);
            result.setInterceptType(handlerResult.getInterceptName());
        }
        return result;
    }
}